﻿@using System.Activities.Statements
@model Isaac.Joy.WebFramework.DtCms.Models.FrameworkViewClass
@{
    Layout = null;
    bool first;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>后台管理中心</title>
    <link type="text/css" href="@Url.BundleContent("~/css/style.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.BundleContent("~/Scripts/jquery-1.10.2.min.js")"></script>
    <script type="text/javascript" src="@Url.BundleContent("~/Scripts/jquery.nicescroll.js")"></script>
    <script type="text/javascript" src="@Url.BundleContent("~/Scripts/lhgdialog/lhgdialog.js?skin=idialog")"></script>
    <script type="text/javascript" src="@Url.BundleContent("~/Scripts/layout.js")"></script>
    <script type="text/javascript">
        //页面加载完成时
        $(function () {
            //检测IE
            if ('undefined' == typeof (document.body.style.maxHeight)) {
                window.location.href = 'ie6update.html';
            }

            $("#nav li").click(function () {
                $("#nav li").removeClass("selected");
                $(this).addClass("selected");
                $("#sidebar-nav .list-box .list-group").hide();
                $("#sidebar-nav .list-box .list-group").eq($("#nav li").index($(this))).show();
            });
            $("#sidebar-nav .list-box .list-group").children("h2").click(function () {
                if ($(this).next("ul").css('display') != 'none') {
                    $(this).next("ul").slideUp(300);
                    return;
                }
                $(this).next("ul").slideDown(300);
            });
            $("#sidebar-nav .list-box .list-group").find("a").click(function () {
                //删除所有的选中样式
                $("#sidebar-nav .list-box .list-group ul li a").removeClass("selected");
                //自身添加样式
                $(this).addClass("selected");
            });
            $("#sidebar-nav .list-box .list-group").find(".folder").parent().unbind("click").click(function () {
                if ($(this).next("ul").css('display') != 'none') {
                    $(this).next("ul").slideUp(300);
                    $(this).find(".folder").removeClass("open");
                    $(this).find(".folder").addClass("close");
                    return;
                }
                $(this).next("ul").slideDown(300);
                $(this).find(".folder").removeClass("close");
                $(this).find(".folder").addClass("open");
            });

            initPopMenuTree();
            linkMenuTree(true, "@Model.DefaultActionId");
        });

        //初始化快捷导航菜单
        function initPopMenuTree() {
            var divWidth = $("#pop-menu .list-box .list-group").length * $("#pop-menu .list-box .list-group").outerWidth();
            var divHeight = $(window).height() * 0.6;
            //如果计算的宽度大于浏览器当前窗口可视宽度
            if (divWidth > ($(window).width() - 60)) {
                divWidth = $(window).width() - 60;
            }
            //计算实际的高度
            var groupHeight = 0;
            $("#pop-menu .list-box .list-group").each(function () {
                if ($(this).height() > groupHeight) {
                    groupHeight = $(this).height();
                }
            });
            if (divHeight > groupHeight) {
                divHeight = groupHeight;
            }
            $("#pop-menu .list-box .list-group").height(groupHeight);
            $("#pop-menu .pop-box").width(divWidth);
            $("#pop-menu .pop-box").height(divHeight);
        }

        //快捷菜单的显示与隐藏
        function triggerMenu(isShow) {
            if (isShow) {
                $("#pop-menu .list-box").getNiceScroll().show();
                $("#pop-menu").css("visibility", "visible");
            } else {
                $("#pop-menu .list-box").getNiceScroll().hide();
                $("#pop-menu").css("visibility", "hidden");
            }
        }

        //定位或跳转到相应的菜单
        function linkMenuTree(islink, navid) {
            var cookieObj = $("#sidebar-nav").find('a[navid="' + navid + '"]');
            if (cookieObj.length > 0) {
                var indexNum = $("#sidebar-nav .list-box .list-group").index(cookieObj.parents(".list-group"));
                $("#nav li").removeClass("selected");
                $("#nav li").eq(indexNum).addClass("selected");
                cookieObj.parents(".list-group").siblings().hide();
                cookieObj.parents(".list-group").show();

                cookieObj.parents("li").each(function () {
                    $(this).siblings().each(function () {
                        if ($(this).children("ul").length > 0) {
                            $(this).children("a").children(".folder").removeClass("open");
                            $(this).children("a").children(".folder").addClass("close");
                            $(this).children("ul").hide();
                        }
                    });
                    if ($(this).children("ul").length > 0) {
                        $(this).children("a").children(".folder").removeClass("close");
                        $(this).children("a").children(".folder").addClass("open");
                    }
                    $(this).children("ul").show();
                });

                cookieObj.parents("ul").show();
                cookieObj.parents("ul").siblings("ul").hide();

                $("#sidebar-nav .list-box .list-group ul li a").removeClass("selected");
                cookieObj.addClass("selected");
                if (islink == true) {
                    frames["mainframe"].location.href = cookieObj.attr("href");
                }
            }
        }
    </script>
</head>

<body class="indexbody">
    <!--全局菜单-->
    <a class="btn-paograms" onclick="triggerMenu(true);"></a>
    <div id="pop-menu" class="pop-menu">
        <div class="pop-box">
            <h1 class="title"><i></i>导航菜单</h1>
            <i class="close" onclick="triggerMenu(false)">关闭</i>
            <div class="list-box" style="overflow: hidden; outline: none;">
                @foreach (var menu in Model.Menus)
                {
                    <div class="list-group">
                        @foreach (var child in menu.Childrens.OrderBy(x => x.Order))
                        {
                            if (!child.IsLeaf)
                            {
                            <h2>@child.Name<i></i></h2>
                                Html.RenderAction("Pop", "Menus", new { childrens = child.Childrens, level = 0 });
                            }
                            else
                            {
                            <h2><a navid="@child.Action.Id" href="@child.Action.Url" target="@(string.IsNullOrEmpty(child.Action.Target) ? "mainframe" : child.Action.Target)">
                                @child.Name
                            </a></h2>
                            }
                        }
                    </div>
                }
            </div>
        </div>
        <i class="arrow">箭头</i>
    </div>
    <!--/全局菜单-->

    <div class="header">
        <div class="header-box">
            <h1 class="logo">后台管理系统</h1>
            <ul id="nav" class="nav">
                @{ first = true; }
                @foreach (var menu in Model.Menus)
                {
                    <li @(first ? "class=selected" : "")><i class="icon-@(menu.Icon)"></i><span>@menu.Name</span></li>
                    { first = false; }
                }
            </ul>
            <div class="nav-right">
                <div class="icon-info">
                    <span>您好，@Model.CurrentUser.Account<br />
                        @Model.CurrentUser.Role.Name
                    </span>
                </div>
                <div class="icon-option">
                    <i></i>
                    <div class="drop-box">
                        @if (Model.QuickMenus.Any())
                        {
                            <div class="arrow"></div>
                            <ul class="drop-item">
                                @foreach (var menu in Model.QuickMenus)
                                {
                                    <li><a href="@menu.Action.Url" target="@(string.IsNullOrEmpty(menu.Action.Target) ? "mainframe" : menu.Action.Target)">@menu.Name</a></li>
                                }
                            </ul>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="main-sidebar">
        <div id="sidebar-nav" class="sidebar-nav">
            <div class="list-box">
                @{ first = true; }
                @foreach (var menu in Model.Menus)
                {
                    <div class="list-group" style="display: @(first ? "block" : "none");">
                        @{ first = false; }
                        @foreach (var child in menu.Childrens.OrderBy(x => x.Order))
                        {
                            if (!child.IsLeaf)
                            {
                            <h2>@child.Name<i></i></h2>
                                Html.RenderAction("Tree", "Menus", new { childrens = child.Childrens, level = 0 });
                            }
                            else
                            {
                            <h2><a href="@child.Action.Url" target="@(string.IsNullOrEmpty(child.Action.Target) ? "mainframe" : child.Action.Target)">
                                @child.Name
                            </a></h2>
                            }
                        }
                    </div>
                }
            </div>
        </div>
    </div>
    <div class="main-container">
        <iframe id="mainframe" name="mainframe" frameborder="0" src="@Url.Action("Welcome")"></iframe>
    </div>
</body>
</html>
